<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Forpastime <Forpastime@qq.com>
// +----------------------------------------------------------------------
namespace api\partner\controller;

use api\partner\model\PartnerModel;
use cmf\controller\RestBaseController;
use think\Db;
use think\db\Query;
use think\facade\Cache;
use think\facade\Request;

class IndexController extends RestBaseController
{
    
    public function login()
    {
       
        $param = $this->request->param();
        if(!empty($param['user_name']) && !empty($param['password'])){
            $partner = new PartnerModel();

            $res = $partner->checkAccount($param['user_name'],$param['password']);

            if($res){
                $token = md5(uniqid()) . md5(uniqid());
                Cache::set('partner:'.$res['id'],$token,60*60*12);

                $data['partner_id']= $res['id'];
                $data['token'] = $token;
                $data['name'] = $res['name'];

                $this->success('登录成功',$data);
            }else{
                $this->error('登录失败');
            }

        }
    }

}